package it.polimi.entities;

import it.polimi.entitiesDTO.PacketDTO;

import java.io.Serializable;

import javax.persistence.*;

import java.util.Date;
import java.util.List;


/**
 * The persistent class for the packet database table.
 * 
 */
@Entity
@NamedQueries ({ @NamedQuery(name=Packet.FIND_ALL, query="SELECT p FROM Packet p"),
				 @NamedQuery(name=Packet.FIND_PACKET, query="SELECT p FROM Packet p WHERE p.id = :id"),
	 			 @NamedQuery(name=Packet.FIND_BY_CITY, query="SELECT p FROM Packet p WHERE p.city = :city"),
	 			 @NamedQuery(name=Packet.FIND_BY_EMPLOYEE, query="SELECT p FROM Packet p WHERE p.employee = :employee")

})

public class Packet implements Serializable {
	private static final long serialVersionUID = 1L;
	
	public static final String FIND_ALL = "Packet.findAll";
	
	public static final String FIND_PACKET = "Packet.findPacket";
	
	public static final String FIND_BY_CITY = "packet.findByCity";
	
	public static final String FIND_BY_EMPLOYEE = "packet.findByEmployee";


	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;

	private String city;

	@Lob
	private String description;

	private String employee;

	@Temporal(TemporalType.DATE)
	@Column(name="END")
	private Date end;

	private int price;

	private int spots;

	@Temporal(TemporalType.DATE)
	@Column(name="START")
	private Date start;

	private boolean visibility;

	//bi-directional many-to-one association to PacketAttraction
	@OneToMany(mappedBy="packetBean")
	private List<PacketAttraction> packetAttractions;

	//bi-directional many-to-one association to PacketFlight
	@OneToMany(mappedBy="packet")
	private List<PacketFlight> packetFlights;
	
	//bi-directional many-to-one association to Hotel
		@ManyToOne
		@JoinColumn(name="hotel")
		private Hotel hotel;

	public Packet() {
		super();
	}
	
	public Packet( PacketDTO packet, Hotel hotel){
		this.city= hotel.getCity();
		this.description= packet.getDescription();
		this.employee=packet.getEmployee();
		this.end=packet.getEnd();
		this.start=packet.getStart();
		this.id=packet.getId();
		this.price=packet.getPrice();
		this.spots=packet.getSpots();
		this.hotel = hotel;
		this.visibility=packet.getVisibility();
		
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getCity() {
		return this.city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getEmployee() {
		return this.employee;
	}

	public void setEmployee(String employee) {
		this.employee = employee;
	}

	public Date getEnd() {
		return this.end;
	}

	public void setEnd(Date end) {
		this.end = end;
	}

	public int getPrice() {
		return this.price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public int getSpots() {
		return this.spots;
	}

	public void setSpots(int spots) {
		this.spots = spots;
	}

	public Date getStart() {
		return this.start;
	}

	public void setStart(Date start) {
		this.start = start;
	}

	public boolean getVisibility() {
		return this.visibility;
	}

	public void setVisibility(boolean visibility) {
		this.visibility = visibility;
	}

	public Hotel getHotel() {
		return hotel;
	}

	public void setHotel(Hotel hotel) {
		this.hotel = hotel;
	}

	public List<PacketAttraction> getPacketAttractions() {
		return this.packetAttractions;
	}

	public void setPacketAttractions(List<PacketAttraction> packetAttractions) {
		this.packetAttractions = packetAttractions;
	}

	public PacketAttraction addPacketAttraction(PacketAttraction packetAttraction) {
		getPacketAttractions().add(packetAttraction);
		packetAttraction.setPacketBean(this);

		return packetAttraction;
	}

	public PacketAttraction removePacketAttraction(PacketAttraction packetAttraction) {
		getPacketAttractions().remove(packetAttraction);
		packetAttraction.setPacketBean(null);

		return packetAttraction;
	}
	
	public List<PacketFlight> getPacketFlights() {
		return this.packetFlights;
	}

	public void setPacketFlights(List<PacketFlight> packetFlights) {
		this.packetFlights = packetFlights;
	}

	public PacketFlight addPacketFlight(PacketFlight packetFlight) {
		getPacketFlights().add(packetFlight);
		packetFlight.setPacket(this);

		return packetFlight;
	}

	public PacketFlight removePacketFlight(PacketFlight packetFlight) {
		getPacketFlights().remove(packetFlight);
		packetFlight.setPacket(null);

		return packetFlight;
	}
	
	public PacketFlight getPacketFlight (int n){
		return packetFlights.get(n);
	}
	public String toString(){
		return "Id: "+this.getId() + " city: "+ this.getCity() + " Description: " +this.getDescription() + " Hotel Name: " + this.getHotel().getName() + "can join from" + this.getStart().toString() + " To " + this.getEnd().toString() + " Open Spots" + this.getSpots() + "Price " + this.getPrice() ;
	}
}